#include <nice2d/actions/delayaction.h>

class DelayActionData
{
public:
    std::function<void()> act;
    float delayTime = 3.0f;
    float elapsedTime = 0.0f;
};

DelayAction::DelayAction(std::function<void()> act, float delay):
    data(new DelayActionData())
{
    data->act = act;
    data->delayTime = delay;
}

DelayAction::~DelayAction()
{
}

float DelayAction::getDelay() const
{
    return data->delayTime;
}

void DelayAction::update(float deletaTime)
{
    if (getStatus() != ActionStatus_Running)
        return;

    data->elapsedTime += deletaTime;
    if (data->elapsedTime >= getDelay()) {
        if (data->act)
            data->act();
        stop();
    }
}
